package com.dgt.trade.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSON;
import com.dgt.trade.entitys.User;
import com.dgt.trade.utils.ConstantsUtils;

/**
 * 基础类
 */
public class BaseController {
	protected Logger logger = LoggerFactory.getLogger(this.getClass());
	@Autowired
	protected HttpServletRequest request;
	@Autowired
	protected HttpServletResponse response;

	protected String redirectTo(String url) {
		StringBuffer rto = new StringBuffer("redirect:");
		rto.append(url);
		return rto.toString();
	}
	
	public User getUser(HttpServletRequest request) {
		Object obj = request.getSession().getAttribute(ConstantsUtils.LOGIN_KEY_FLAG);
		if(obj!=null) {
			User user= JSON.parseObject((String) obj, User.class);
			return user;
		}
		return null;
	}
}
